﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Pagebase/PageEdit.Master" AutoEventWireup="true" CodeBehind="S_roleSet.aspx.cs" Inherits="webnew.Systems.S_roleSet" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script type="text/javascript">
    function GoClick() {

        var obj = event.srcElement;
        if (obj.tagName.toUpperCase() != "INPUT") return;
        var tb = obj.parentElement.parentElement.parentElement.parentElement; //当前节点的Table
        SelAllChildren(tb, obj.checked);

        tb = tb.parentElement; //

        while (true) {
            tb = tb.previousSibling
            if (tb == null) return;
         SetParentCheckBoxStatus(tb);
            tb = tb.parentElement
            if (tb == null) return;
        }

    }

    function SelAllChildren(tb, bChecked) {
        var div = tb.nextSibling;
        try {
            for (var i = 0; i < div.children.length; i++) {

                if (div.children[i].tagName.toUpperCase() != "TABLE") continue;
                var chkBox = FindRowCheckBox(div.children[i].rows[0]);
                if (chkBox == null) continue;
                chkBox.checked = bChecked;

                SelAllChildren(div.children[i], bChecked);

            }
        } catch (e) { }
    }
    
    //树形点击效果 修改版本1
    function SetParentCheckBoxStatus(objTb) {
        var div = objTb.nextSibling;

        var bSelAll = true;
        var bSelOne = false;
        for (var i = 0; i < div.children.length; i++) {

            if (div.children[i].tagName.toUpperCase() != "TABLE") continue;

            var chkBox = FindRowCheckBox(div.children[i].rows[0]);

            if (!chkBox.checked) {
                bSelAll = false;
            } else {
                bSelOne = true;
            }
        }


        if (objTb.rows != null) {
            var chkBox = FindRowCheckBox(objTb.rows[0])
            if (bSelAll == false) chkBox.checked=true;
            else chkBox.checked = bSelOne;

        }
    }
    //树形点击效果 原版本
//    function SetParentCheckBoxStatus(objTb) {
//        var div = objTb.nextSibling;

//        var bSelAll = true;
//        var bSelOne = false;
//        for (var i = 0; i < div.children.length; i++) {

//            if (div.children[i].tagName.toUpperCase() != "TABLE") continue;

//            var chkBox = FindRowCheckBox(div.children[i].rows[0]);

//            if (!chkBox.checked) {
//                bSelAll = false;
//            } else {
//                bSelOne = true;
//            }
//        }


//        if (objTb.rows != null) {
//            var chkBox = FindRowCheckBox(objTb.rows[0])
//            chkBox.checked = bSelOne;

//        }
//    }

    function FindRowCheckBox(tr) {
        for (var i = 0; i < tr.cells.length; i++) {
            if (tr.cells[i].firstChild.tagName == "INPUT") {
                return tr.cells[i].firstChild;
            }
        }
    }



    </script> 
<div id="EditContentbox">
    <fieldset id="EditBox" runat="server" class="EditBox">
        <table id="EditTbl" cellpadding='2' cellspacing='1'>
        <tr>
                <td align="left" class="td1" style=" text-align:left !important;"> 
                    <asp:Literal ID="ltName" runat="server"></asp:Literal>
                 &nbsp;
                 </td>
            </tr>
            <tr>
                <td align="left" class="td1" style=" text-align:left !important;">                  
           当前角色用户：
                 
                  
                    <asp:LinkButton ID="lbtnView" runat="server" onclick="lbtnView_Click">显示详细用户</asp:LinkButton>
                    <asp:LinkButton ID="lbtnHide" runat="server" onclick="lbtnHide_Click" 
                        Visible="False">隐藏详细用户</asp:LinkButton>
                 
                 </td>
            </tr>
           <tr>
            <td align="left" class="td1" style=" text-align:left !important;"> 
                    <asp:GridView ID="grdView" runat="server" Width="100%" 
                    AutoGenerateColumns="False" DataKeyNames="id" CssClass="dgv" 
                          PageSize="15" Visible="False">
                <Columns>                    
                    <asp:BoundField DataField="loginid" HeaderText="用户名" >
                    <ItemStyle Width="110px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="truename" HeaderText="姓名" >
                    <ItemStyle Width="90px" />
                    </asp:BoundField>                 
                    <asp:BoundField DataField="lastLogTime" HeaderText="最近登录时间" >
                    <ItemStyle Width="150px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="remark" HeaderText="备注" />
                </Columns>
            <HeaderStyle CssClass="x-panel-header" />
            <AlternatingRowStyle CssClass="dgvitem1" />
            <RowStyle CssClass="dgvitem" />
            </asp:GridView>
             </td>
          </tr>
            <tr>
                <td align="left" style="background:white;">
                    <asp:TreeView ID="TreeView1" runat="server" onclick="GoClick()"  
                        ShowCheckBoxes="All" ExpandDepth="1" 
                        
                        PopulateNodesFromClient="False">
                    </asp:TreeView>
                 </td>
            </tr>
            </table>
    </fieldset>
    </div>
</asp:Content>
